﻿Module modCommon

    Public Function getMsgStr(ByVal msgId As String, Optional ByVal args1 As String = "", Optional ByVal args2 As String = "", Optional ByVal args3 As String = "") As String

        If String.IsNullOrEmpty(args1) AndAlso String.IsNullOrEmpty(args2) AndAlso String.IsNullOrEmpty(args3) Then
            getMsgStr = htMsgMst(msgId)
            Exit Function

        ElseIf Not String.IsNullOrEmpty(args1) AndAlso Not String.IsNullOrEmpty(args2) AndAlso String.IsNullOrEmpty(args3) Then
            getMsgStr = String.Format(htMsgMst(msgId), args1, args2)
            Exit Function
        ElseIf Not String.IsNullOrEmpty(args1) AndAlso Not String.IsNullOrEmpty(args2) AndAlso Not String.IsNullOrEmpty(args3) Then
            getMsgStr = String.Format(htMsgMst(msgId), args1, args2, args3)
            Exit Function
        Else
            getMsgStr = String.Format(htMsgMst(msgId), args1, args2)
            Exit Function
        End If

    End Function

    ''' <summary>
    ''' 检查是否为空
    ''' </summary>
    ''' <param name="Sender">要检查的控件</param>
    ''' <returns></returns>
    Public Function chkEmpty(Sender As Object) As Boolean
        If Sender.text = "" Then
            MsgBox(getMsgStr("msg001", Sender.tag))
            Sender.Select()
            Return False
        End If
        Return True
    End Function

    ''' <summary>
    ''' 检查是否为空
    ''' </summary>
    ''' <param name="Sender">要检查的控件</param>
    ''' <returns></returns>
    Public Function chkZero(Sender As Object) As Boolean
        If Sender.text = "0" Then
            MsgBox(getMsgStr("msg002", Sender.tag))
            Sender.Select()
            Return False
        End If
        Return True
    End Function

    ''' <summary>
    ''' 检查是否为负数
    ''' </summary>
    ''' <param name="Sender">要检查的控件</param>
    ''' <returns></returns>
    Public Function chkNegative(Sender As Object) As Boolean
        If CInt(Sender.text) < 0 Then
            MsgBox(getMsgStr("msg041", Sender.tag))
            Sender.Select()
            Return False
        End If
        Return True
    End Function

    Public Function getServerDateTime() As DateTime
        Dim dt As DataTable = New DataTable
        Dim szSql As String = String.Empty
        szSql &= "SELECT CURRENT_TIMESTAMP(9) "
        dt = DBacs.ExecuteSql(szSql, -1)
        Return dt.Rows(0)(0)
    End Function

End Module
